package com.qf.erp_system_admin.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.erp_system_admin.entity.Client;
import com.qf.erp_system_admin.entity.Depot;
import com.qf.erp_system_admin.service.DepotService;
import com.qf.erp_system_admin.util.R;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/depot")
public class DepotContoroller {
    private Logger logger = LogManager.getLogger(DepotContoroller.class);
    @Autowired
    private DepotService depotService;
    @GetMapping("/list")
    public R findAll(@RequestParam HashMap<String,String> map) {
        int pageNum = Integer.parseInt(map.get("pageNum"));
        int pageSize = Integer.parseInt(map.get("pageSize"));
        PageHelper.startPage(pageNum,pageSize);
        List<Depot> depot = depotService.findAll(map);
        PageInfo<Depot> info = new PageInfo<>(depot);
        System.out.println("info = " + info);
        return  R.ok(info);
    }
    //单个删除
    @GetMapping("/del")
    public R del(int depId) {
        boolean isok = depotService.del(depId);
        return  R.ok(isok);
    }
    //批量删除
    @GetMapping ("/delBatch")
    public R delBatch(@RequestParam List<Integer> ids) {
        boolean isok =  depotService.delBatch(ids);
        return R.ok(isok);
    }
    //添加
    @PostMapping("/add")
    public R add(@RequestBody Depot  depot) {
        boolean isok =  depotService.add(depot);
        return R.ok(isok);
    }
    //更新
    @PostMapping("/up")
    public R up(@RequestBody Depot depot) {
        boolean isok =  depotService.up(depot);
        return R.ok(isok);
    }
}
